import 'dart:io';
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:image_pickers/image_pickers.dart';
import 'package:top_foundation/utils/ex/image.dart';
import 'package:whale/helper/utils/util.dart';

class WaterMarker extends StatefulWidget {
  const WaterMarker({
    super.key,
    required this.repaintKey,
    required this.img,
    required this.text,
  });
  final GlobalKey repaintKey;
  final Media img;
  final String text;
  @override
  State<WaterMarker> createState() => _WaterMarkerState();
}

class _WaterMarkerState extends State<WaterMarker> {
  @override
  Widget build(BuildContext context) {
    return RepaintBoundary(
      key: widget.repaintKey,
      child: Stack(
        children: [
          IImage.net(url: widget.img.path),
          if (widget.text.isNotEmpty)
            Positioned.fill(
              child: ClipRect(
                child: ListView(
                  physics: const NeverScrollableScrollPhysics(),
                  children: List.generate(100, (index) {
                    return SingleChildScrollView(
                      scrollDirection: Axis.horizontal,
                      physics: const NeverScrollableScrollPhysics(),
                      child: RichText(
                          maxLines: 1,
                          text: WidgetSpan(
                              child: Row(
                            children: List.generate(
                                100,
                                (index) => Row(
                                      children: [
                                        Transform.rotate(
                                          angle: -pi / 4,
                                          child: Text(
                                            widget.text,
                                            style: TextStyle(
                                              color: const Color(0x88ffffff),
                                              fontSize: 16.sp,
                                            ),
                                          ),
                                        ),
                                        const SizedBox(
                                          width: 50,
                                          height: 100,
                                        ),
                                      ],
                                    )),
                          ))),
                    );
                  }),
                ),
              ),
            ),
        ],
      ),
    );
  }
}
